<?php

$formatParam = getRequestParam('format');

function getFormatParam() {
	global $formatParam;
	return $formatParam;
}

function selectOptionOnFormatMatch($formatOption) {
	return getFormatParam() === $formatOption ? 'selected="selected"' : '';
}

function isJsonFormatSelected() {
	$format = getFormatParam();
	return $format === 'json' || empty($format);
}

?>

<script type="text/javascript">
	function toggleCallback() {
		var formatSelect = document.getElementById("formatSelect").value;
		var callbackStyle = "";
		if (formatSelect !== "json") {
			callbackStyle = "display: none;";
		}
		document.getElementById("callbackRow").setAttribute("style", callbackStyle);
	}
</script>

<tr>
	<td class="Label">format:</td>
	<td>
		<select id="formatSelect" class="Input" name="format" onchange="toggleCallback()">
			<option value="json" <?= selectOptionOnFormatMatch('json') ?>>JSON</option>
			<option value="xml" <?= selectOptionOnFormatMatch('xml') ?>>XML</option>
			<option value="rss" <?= selectOptionOnFormatMatch('rss') ?>>RSS</option>
		</select>
	</td>
</tr>
<tr id="callbackRow" style="<?= !isJsonFormatSelected() ? 'display: none; ' : '' ?>">
	<td class="Label">callback:</td>
	<td><input type="text" class="Input" name="callback" value="ggCallback"/></td>
</tr>
<tr>
	<td class="Label">&nbsp;</td>
	<td>&nbsp;</td>
</tr>
